package com.custom.windows;

import com.smartnsoft.fractory.R;
import com.smartnsoft.fractory.R.id;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

/**
 * The Quality Pop up.
 * 
 * @author Willy Noel
 * @since 2011.05.25
 */

public final class QualityPopup extends CustomPopupWindow
{

  private final LayoutInflater inflater;

  private Context context;

  private View root;

  private SeekBar qualitySeekBar;

  private TextView qualityNumber;

  public Button qualityValidateButton;

  public Button qualityCancelButton;

  public TextView qualityTitle;

  private View view;

  private int maxIteration;
  
  public void setMaxIteration(int maxIteration)
  {
    this.maxIteration = maxIteration;
  }

  public int getMaxIteration()
  {
    return maxIteration;
  }
  
  public QualityPopup(View anchor)
  {
    super(anchor);
    context = anchor.getContext();
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }

  public void setRootView(int ressources)
  {
    root = inflater.inflate(ressources, null);
    setContentView(root);
    view = root;
    qualitySeekBar = (SeekBar) view.findViewById(R.id.qualitySeekBar);
    qualityValidateButton = (Button) view.findViewById(R.id.okButtonQuality);
    qualityCancelButton = (Button) view.findViewById(R.id.cancelButtonQuality);
    qualityNumber = (TextView) view.findViewById(R.id.qualityNumber);
    qualityTitle = (TextView) view.findViewById(R.id.qualityText);

    qualitySeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
    {
      public void onStopTrackingTouch(SeekBar seekBar)
      {

      }
      public void onStartTrackingTouch(SeekBar seekBar)
      {

      }
      public void onProgressChanged(SeekBar seekBar, int progress,
          boolean fromUser)
      {
        maxIteration =  progress;
        qualityNumber.setText(String.valueOf(progress));
      }
    });

  }

  /**
   * Show popup window
   */
  public void show()
  {
    preShow();
    root.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    root.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    window.showAtLocation(this.anchor, Gravity.CENTER, 0, 0);
  }



}
